<?php

require_once realpath(__DIR__ . '/../libs/php-i18n-master/i18n.class.php');

Class Language_Manager {

    private static $instance = null;

    public static function getInstance() {
        return self::$instance == null ? self::$instance = new Language_Manager() : self::$instance;
    }

    private function __construct() {
        $language = $this->getLanguage();
        $fileLanguage = realpath(__DIR__ . '/../libs/php-i18n-master/lang/lang_' . $language . '.ini');
        $langCache = realpath(__DIR__ . '/../libs/php-i18n-master/langcache/');
        $i18n = new i18n($fileLanguage, $langCache, 'it');
        $i18n->init();
    }

    private function getLanguage() {
        $language = "";
        //$lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
        $lang = "it";
        if (isset($_GET) && isset($_GET['lang']) && $_GET['lang'] == 'en') {
            $lang = "en";
        }
        switch ($lang) {
            case "en":
                //echo "PAGE IT";
                $language = "en";
                break;
            default:
                $language = "it";
                break;
        }
        return $language;
    }

}
